/*
 * @Author: Smthie Smthie@qq.com
 * @Date: 2024-05-13 10:16:12
 * @LastEditors: Smthie Smthie@qq.com
 * @LastEditTime: 2024-05-30 12:04:20
 * @FilePath: \ProtocolTool\src\renderer\src\utils\request.ts
 */
import axios from 'axios'
import { message } from 'ant-design-vue'

const request = axios.create({
  baseURL: import.meta.env.RENDERER_VITE_BASE_API,
  timeout: 30000
})

// 请求拦截器
request.interceptors.request.use((config) => {
  return config
})

// 响应拦截器
request.interceptors.response.use(
  (response) => {
    return response.data
  },
  (error) => {
    console.log('response error:', error)
    if (error.response?.statusText !== 'Internal Server Error' && error.code !== 'ERR_NETWORK') {
      const msg =
        error.response?.data?.msg || error.response?.data?.error || error.response?.statusText
      message.error(msg)
    }
    return Promise.reject(error)
  }
)

export default request
